package com.hqj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hqj.dao.QuestionBankMapper;
import com.hqj.entity.QuestionBank;
import com.hqj.service.QuestionBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 黄啟军
 * @version 1.0
 * @date 2020/8/4 0004
 */
@Service
public class QuestionBankServiceImpl implements QuestionBankService {

    @Resource
    private QuestionBankMapper questionBankMapper;

    @Override
    public List<QuestionBank> findList(String seek) {
        QueryWrapper<QuestionBank> wrapper = new QueryWrapper<>();
        wrapper.like("content",seek).or()
         .like("fk_type_id",seek).or()
         .like("choice",seek).or()
         .like("ans",seek);
        return questionBankMapper.selectList(wrapper);
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Long id){
        QuestionBank bank = questionBankMapper.selectById(id);
        bank.setIsDelete(1);
        questionBankMapper.updateById(bank);
    }

    /**
     * 修改QuestionBank
     * @param questionBank
     */
    @Override
    public void update(QuestionBank questionBank){
        questionBankMapper.updateById(questionBank);
    }

    /**
     * 增加QuestionBank
     * @param questionBank
     */
    @Override
    public void add(QuestionBank questionBank){
        questionBankMapper.insert(questionBank);
    }

    /**
     * 根据ID查询QuestionBank
     * @param id
     * @return
     */
    @Override
    public QuestionBank findById(Long id){
        return  questionBankMapper.selectById(id);
    }

    /**
     * 查询QuestionBank全部数据
     * @return
     */
    @Override
    public List<QuestionBank> findAll() {
        return questionBankMapper.selectList(null);
    }
}
